package com.baitengsoft.patentapimonitor.api.controller;

import com.baitengsoft.patentapimonitor.api.entity.WebUserinfoEntity;
import com.baitengsoft.patentapimonitor.api.model.CfgDictionaryInfo;
import com.baitengsoft.patentapimonitor.api.model.WebApplyChangeInfo;
import com.baitengsoft.patentapimonitor.api.model.param.SearchExpiryNoticeParam;
import com.baitengsoft.patentapimonitor.api.service.CfgDictionaryService;
import com.baitengsoft.patentapimonitor.api.service.PacPatentinfoService;
import com.baitengsoft.patentapimonitor.common.utils.PageResult;
import com.baitengsoft.patentapimonitor.common.utils.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author Chen 2018/1/18
 */
@RestController
@RequestMapping("/api/v1/web/applychange")
@Api(value = "前台-专利监控-专利权变更",description = "专利权变更")
public class WebApplyChangeController extends AbstractController {
    @Autowired
    private CfgDictionaryService cfgDictionaryService;
    @Autowired
    private PacPatentinfoService pacPatentinfoService;
    /**
     * 获取筛选参数
     */
    @ApiOperation(value ="获取查询参数-专利类型(patTypes)")
    @GetMapping("/param")
    @ResponseBody
    public Res getPatType(){
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("用户信息获取失败");
        }
        //获取专利类型和value
        List<CfgDictionaryInfo> patTypes = cfgDictionaryService.getNameAndValueByCode("1003");
        return Res.ok().put("patTypes",patTypes);
    }

    @ApiOperation(value ="获取转入列表")
    @GetMapping("/inlist")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "patType", value = "专利类型", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "patNum", value = "申请号", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "ApplyPersonLast", value = "变更后权力人", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "startDate", value = "开始时间", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "endDate", value = "结束时间", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageNumber", value = "页号", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页多少条", required = true)
    })
    public Res getApplyChangeInList(@ApiIgnore SearchExpiryNoticeParam param){
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("用户信息获取失败");
        }
        PageResult<WebApplyChangeInfo> result = pacPatentinfoService.getApplyChangeInList(userInfo.getPlatformid(), param);
        return Res.ok().put("list",result);

    }

    @ApiOperation(value ="获取转出列表")
    @GetMapping("/outlist")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "patType", value = "专利类型", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "patNum", value = "申请号", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "ApplyPersonLast", value = "变更后权力人", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "startDate", value = "开始时间", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "endDate", value = "结束时间", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageNumber", value = "页号", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页多少条", required = true)
    })
    public Res getApplyChangeOutList(@ApiIgnore SearchExpiryNoticeParam param){
        WebUserinfoEntity userInfo = getUserInfo();
        if (userInfo ==null || userInfo.getPlatformid()==null){
            return Res.error("用户信息获取失败");
        }
        PageResult<WebApplyChangeInfo> result = pacPatentinfoService.getApplyChangeOutList(userInfo.getPlatformid(), param);
        return Res.ok().put("list",result);
    }
}
